package com.ruoyi.web.controller.item;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.item.domain.ItemGoodssellcontrast;
import com.ruoyi.item.service.IItemGoodssellcontrastService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 在线商品销售Controller
 *
 * @author ruoyi
 * @date 2022-03-22
 */
@Api("在线商品销售Controller")
@RestController
@RequestMapping("/item/goodssellcontrast")
public class ItemGoodssellcontrastController extends BaseController
{
    @Autowired
    private IItemGoodssellcontrastService itemGoodssellcontrastService;

    /**
     * 查询在线商品销售列表
     */
    @ApiOperation("查询在线商品销售列表")
    @PreAuthorize("@ss.hasPermi('item:goodssellcontrast:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemGoodssellcontrast itemGoodssellcontrast)
    {
        startPage();
        List<ItemGoodssellcontrast> list = itemGoodssellcontrastService.selectItemGoodssellcontrastList(itemGoodssellcontrast);
        return getDataTable(list);
    }

    /**
     * 导出在线商品销售列表
     */
    @ApiOperation("导出在线商品销售列表")
    @PreAuthorize("@ss.hasPermi('item:goodssellcontrast:export')")
    @Log(title = "在线商品销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemGoodssellcontrast itemGoodssellcontrast)
    {
        List<ItemGoodssellcontrast> list = itemGoodssellcontrastService.selectItemGoodssellcontrastList(itemGoodssellcontrast);
        ExcelUtil<ItemGoodssellcontrast> util = new ExcelUtil<ItemGoodssellcontrast>(ItemGoodssellcontrast.class);
        util.exportExcel(response, list, "在线商品销售数据");
    }

    /**
     * 获取在线商品销售详细信息
     */
    @ApiOperation("获取在线商品销售详细信息")
    @PreAuthorize("@ss.hasPermi('item:goodssellcontrast:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") Long goodsId)
    {
        return AjaxResult.success(itemGoodssellcontrastService.selectItemGoodssellcontrastByGoodsId(goodsId));
    }

    /**
     * 新增在线商品销售
     */
    @ApiOperation("新增在线商品销售")
    @PreAuthorize("@ss.hasPermi('item:goodssellcontrast:add')")
    @Log(title = "在线商品销售", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemGoodssellcontrast itemGoodssellcontrast)
    {
        return toAjax(itemGoodssellcontrastService.insertItemGoodssellcontrast(itemGoodssellcontrast));
    }

    /**
     * 修改在线商品销售
     */
    @ApiOperation("修改在线商品销售")
    @PreAuthorize("@ss.hasPermi('item:goodssellcontrast:edit')")
    @Log(title = "在线商品销售", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemGoodssellcontrast itemGoodssellcontrast)
    {
        return toAjax(itemGoodssellcontrastService.updateItemGoodssellcontrast(itemGoodssellcontrast));
    }

    /**
     * 删除在线商品销售
     */
    @ApiOperation("删除在线商品销售")
    @PreAuthorize("@ss.hasPermi('item:goodssellcontrast:remove')")
    @Log(title = "在线商品销售", businessType = BusinessType.DELETE)
    @DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable Long[] goodsIds)
    {
        return toAjax(itemGoodssellcontrastService.deleteItemGoodssellcontrastByGoodsIds(goodsIds));
    }
}
